import 'package:flutter/material.dart';
import 'translations/en.dart';
import 'translations/zh.dart';

class AppLocalizations {
  final Locale locale;

  AppLocalizations(this.locale);

  static AppLocalizations of(BuildContext context) {
    return Localizations.of<AppLocalizations>(context, AppLocalizations)!;
  }

  static final Map<String, Map<String, String>> _localizedValues = {
    'en': en,
    'zh': zh,
  };

  String get home => _localizedValues[locale.languageCode]!['home']!;
  String get record => _localizedValues[locale.languageCode]!['record']!;
  String get statistics => _localizedValues[locale.languageCode]!['statistics']!;
  String get settings => _localizedValues[locale.languageCode]!['settings']!;
}

class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
  const AppLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) => ['en', 'zh'].contains(locale.languageCode);

  @override
  Future<AppLocalizations> load(Locale locale) {
    return Future.value(AppLocalizations(locale));
  }

  @override
  bool shouldReload(AppLocalizationsDelegate old) => false;
}